<template>
  <el-dialog
    :title="title"
    destroy-on-close
    append-to-body
    :visible.sync="show"
    width="1000px"
    :before-close="cancel">
    <el-table show-summary :summary-method="handleSum" ref="TableRef" :data="tabelDeta">
      <el-table-column show-overflow-tooltip :label="$t('订单号')" align="center" prop="orderNo" />
      <el-table-column show-overflow-tooltip :label="$t('sku编号')" align="center" prop="skuNo" />
      <el-table-column show-overflow-tooltip :label="$t('sku申请id')" align="center" prop="applyId" />
      <el-table-column show-overflow-tooltip :label="$t('申请时价格')" align="center" prop="applyPrice" />
      <el-table-column show-overflow-tooltip :label="$t('需要付款的数量')" align="center" prop="handleWaitPayNum" />
      <el-table-column show-overflow-tooltip :label="$t('消耗该申请里的数量')" align="center" prop="handleNum" />
      <el-table-column show-overflow-tooltip :label="$t('已付款数量')" align="center" prop="handlePayNum" />
      <el-table-column show-overflow-tooltip :label="$t('已付款总价')" align="center" prop="payTotal" />
      <el-table-column show-overflow-tooltip :label="$t('未付款总价')" align="center" prop="waitPayTotal" />
      <el-table-column show-overflow-tooltip :label="$t('sku总价值')" align="center" prop="totalPrice" />
    </el-table>
  </el-dialog>
</template>
<script>
import handleTableSum from '@/utils/handleSum'

import { billSellerFeeInfo } from '@/api/bill/seller'
export default {
  activated() {
    this.$nextTick(() => this.$refs['TableRef']?.doLayout())
  },
  props: {
    data: {
      type: Object,
      default: () => {},
    },
    title: {
      type: String,
    },
    /**
     * 控制显示隐藏
     */
    show: {
      type: Boolean,
      default: false,
    },
  },
  data() {
    return {
      tabelDeta: [],
    }
  },
  methods: {
    handleSum(param) {
      /**
       * 需要进行统计的字段
       */
      const data = handleTableSum(param, ['waitPayTotal','totalPrice'],'合计',0 )
      console.log(`data ==>`, JSON.parse(JSON.stringify(data)))
      return data
    },

    cancel() {
      console.log('执行了')
      this.$emit('update:show', false)
    },
  },
  watch: {
    show: function (params) {
      if (params) {
        billSellerFeeInfo({ id: this.data.id, type: 1 }).then((res) => {
          this.tabelDeta = res.data.skuBillData
        })
      }
    },
  },
}
</script>
